package com.elitel.frame.base.component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.annotation.Resource;

import com.elitel.common.mongodb.MongoDBUtil;
import com.elitel.common.mongodb.QueryInfo;
import com.elitel.frame.business.dao.ext.ExecuteSqlMapper;
import com.mongodb.client.MongoDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
//import com.elitel.common.redis.RedisDbIndex;
//import com.elitel.common.redis.service.RedisCacheService;
import com.elitel.frame.base.service.TreeConfigFileService;
import com.elitel.frame.main.entity.BaseTreeconfig;
import com.elitel.frame.main.entity.CfgDb;
import com.elitel.frame.main.entity.CfgExttree;
import com.elitel.frame.main.entity.CfgField;
import com.elitel.frame.main.entity.CfgTable;
import com.elitel.frame.main.entity.vo.PageResponseVo;
import com.elitel.frame.main.entity.ext.Census;
import com.elitel.frame.main.entity.ext.TreeConfig;

@Component("redisCacheTreeConfig")
public class RedisCacheTreeConfig {
    private CfgDb cfgDb;
    @Resource
    private RedisCacheComponent redisCacheComponent;
//    @Resource
//    private RedisCacheService redisCacheService;

    @Autowired
    private TreeConfigFileService treeConfigFileService;
    @Autowired
    private CacheCollections cacheCollections;
    @Autowired
    private ExecuteSqlMapper executeSqlMapper;


    // 增删改操作后添加刷新缓存
    @CachePut(cacheNames = CacheConfig.DEFAULT, key = "'CFG_TREECONFIG_'+#key")
    public List<BaseTreeconfig> setTreeConfig(String key) {
//        int rdi = RedisDbIndex.value;
//        PageResponseVo<BaseTreeconfig> pageResponseVos = treeConfigServiceImpl.selectTreeConfigAll(key);
//        key = "CFG_TREECONFIG_" + key;
//        String basicServerString = JSON.toJSONString(pageResponseVos.getRows());
//        redisCacheService.saveObject(key, basicServerString, rdi);
        PageResponseVo<BaseTreeconfig> pageResponseVos = treeConfigFileService.selectTreeConfigAll(key);
        List<BaseTreeconfig> rows = pageResponseVos.getRows();
        return rows;
    }

    // 根据configid获取字段类
    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "'CFG_FIELD_'+#dbKey")
    public CfgField cfgFieldRedisCache(String configid, String dbKey) {
//		int rdi = RedisDbIndex.value;
//		CfgField vField = new CfgField();
//		String key = "CFG_FIELD_" + dbKey;
//		System.out.println(redisCacheService.stringExists(key, rdi));
//		if (redisCacheService.stringExists(key, rdi)) {
//			String cfgStr = redisCacheService.getObject(key, rdi);
//			System.out.println(cfgStr);
//			if (cfgStr == null) {
//				vField = treeConfigServiceImpl.getAllListCfgField(configid, dbKey);
//				String extendStr = JSON.toJSONString(vField);
//				redisCacheService.saveObject(key, extendStr, rdi);
//			} else {
//				vField = (CfgField) JSON.parseObject(cfgStr, CfgField.class);
//			}
//		} else {
//			vField = treeConfigServiceImpl.getAllListCfgField(configid, dbKey);
//			String extendStr = JSON.toJSONString(vField);
//			redisCacheService.saveObject(key, extendStr, rdi);
//		}

        CfgField vField = treeConfigFileService.getAllListCfgField(configid, dbKey);
        return vField;
    }

    // 根据guid获取资源树集合
    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "'CFG_TREECONFIG_'+#dbKey")
    public List<BaseTreeconfig> getBaseTreeCache(String dbKey) {
//        int rdi = RedisDbIndex.value;
//        String dbKeys = "CFG_TREECONFIG_" + dbKey;
//        List<BaseTreeconfig> list = new ArrayList<>();
//        if (redisCacheService.stringExists(dbKeys, rdi)) {
//            String cfgStr = redisCacheService.getObject(dbKeys, rdi);
//            list = (List<BaseTreeconfig>) JSON.parseArray(cfgStr, BaseTreeconfig.class);
//        } else {
//            PageResponseVo<BaseTreeconfig> pageResponseVos = treeConfigServiceImpl.selectTreeConfigAll(dbKey);
//            list = pageResponseVos.getRows();
//            String extendStr = JSON.toJSONString(list);
//            redisCacheService.saveObject(dbKeys, extendStr, rdi);
//        }


        PageResponseVo<BaseTreeconfig> pageResponseVos = treeConfigFileService.selectTreeConfigAll(dbKey);
        List<BaseTreeconfig> list = pageResponseVos.getRows();
        return list;
    }

    // 根据层级和资源树服务id获取单个类
    // 根据guid获取资源树集合
    public BaseTreeconfig getBaseTreeCacheOne(String dbKey, Integer grade) {
//        int rdi = RedisDbIndex.value;
//        String dbKeys = "CFG_TREECONFIG_" + dbKey;
//        List<BaseTreeconfig> list = new ArrayList<>();
//        BaseTreeconfig baseTreeconfig = null;
//        if (redisCacheService.stringExists(dbKeys, rdi)) {
//            // String cfgStr = redisCacheService.getObject(dbKeys, rdi);
//            // list =
//            // (List<BaseTreeconfig>)JSON.parseArray(cfgStr,BaseTreeconfig.class);
//            // }else{
//            PageResponseVo<BaseTreeconfig> pageResponseVos = treeConfigServiceImpl.selectTreeConfigAll(dbKey);
//            list = pageResponseVos.getRows();
//            String extendStr = JSON.toJSONString(list);
//            redisCacheService.saveObject(dbKeys, extendStr, rdi);
//        }
//        if (list.size() == 0) {
//            PageResponseVo<BaseTreeconfig> pageResponseVos = treeConfigServiceImpl.selectTreeConfigAll(dbKey);
//            list = pageResponseVos.getRows();
//            String extendStr = JSON.toJSONString(list);
//            redisCacheService.saveObject(dbKeys, extendStr, rdi);
//        }

        BaseTreeconfig baseTreeconfig = null;
        List<BaseTreeconfig> baseTrees = cacheCollections.getBaseTrees(dbKey);
        for (BaseTreeconfig b : baseTrees) {
            if (b.getGrade() == grade) {
                baseTreeconfig = b;
            }
        }
        return baseTreeconfig;
    }

    // 根据key获取cfgdb
    public CfgDb selectCfgDbOne(String dbkey) {
//        int rdi = RedisDbIndex.value;
//        String key = "CFG_DB";
//        CfgDb cfgDb = null;
//        List<CfgDb> list = new ArrayList<>();
////		if (redisCacheService.stringExists(key, rdi)) {
////			String cfgStr = redisCacheService.getObject(key, rdi);
////			list = (List<CfgDb>) JSON.parseArray(cfgStr, CfgDb.class);
////		} else {
//        list = treeConfigServiceImpl.selectCfgDbList();
//        String extendStr = JSON.toJSONString(list);
//        redisCacheService.saveObject(key, extendStr, rdi);
////		}

        CfgDb cfgDb = null;
        List<CfgDb> cfgDbs = cacheCollections.getCfgDbs();
        for (CfgDb c : cfgDbs) {
            if (dbkey.equals(c.getDbKey())) {
                cfgDb = c;
            }
        }
        return cfgDb;
    }

    // 根据configid 获取table表类
    public CfgTable selectCfgTableOne(String dbkey) {
//        int rdi = RedisDbIndex.value;
//        String key = "CFG_TABLE_ALL";
//        CfgTable cfgTable = null;
//        List<CfgTable> list = new ArrayList<>();
//        list = treeConfigServiceImpl.selectCfgTableAll();
//        String extendStr = JSON.toJSONString(list);
//        redisCacheService.saveObject(key, extendStr, rdi);

        CfgTable cfgTable = null;
        List<CfgTable> allCfgTables = cacheCollections.getAllCfgTables();
        for (CfgTable c : allCfgTables) {
            if (dbkey.equals(c.getDtConfigId())) {
                cfgTable = c;
            }
        }
        return cfgTable;
    }

    // 存取资源树左侧列表
    @CachePut(cacheNames = CacheConfig.DEFAULT, key = "'TREE_TREECONFIG'")
    public List<Census> setTreeing() {
//        int rdi = RedisDbIndex.value;
//        String dbkey = "TREE_TREECONFIG";
//        List<Census> list = treeConfigServiceImpl.getTreeList();
//        String basicServerString = JSON.toJSONString(list);
//        redisCacheService.saveObject(dbkey, basicServerString, rdi);
        List<Census> list = treeConfigFileService.getTreeList();
        return list;
    }

    // 獲取資源樹
    public CfgExttree getTreeExt(String id) {
//        int rdi = RedisDbIndex.value;
//        String dbkey = "TREE_TREECONFIG_ALL";
//        CfgExttree cfgExttree = null;
//        List<CfgExttree> list = null;
//        if (redisCacheService.stringExists(dbkey, rdi)) {
//            String cfgStr = redisCacheService.getObject(dbkey, rdi);
//            list = (List<CfgExttree>) JSON.parseArray(cfgStr, CfgExttree.class);
//        } else {
//            list = treeConfigServiceImpl.getTreeListaLL();
//            String extendStr = JSON.toJSONString(list);
//            redisCacheService.saveObject(dbkey, extendStr, rdi);
//
//        }

        CfgExttree cfgExttree = null;
        List<CfgExttree> allTreesExt = cacheCollections.getAllTreesExt();

        for (CfgExttree c : allTreesExt) {
            if (id.equals(c.getGuid())) {
                cfgExttree = c;
            }
        }
        return cfgExttree;
    }

    public List<Map<String, Object>> executequerySql(CfgDb cfgDb, String sqlString) {
        List<Map<String, Object>> list = treeConfigFileService.executequerySql(sqlString);
        return list;
    }

    // redis缓存资源树数据
    @CachePut(cacheNames = CacheConfig.DEFAULT, key = "'TREE_CONFIG_ALL'+#guid")
    public String selectTreeConfig(String guid) {
//        int rdi = RedisDbIndex.value;
        CfgExttree cfgExttree = treeConfigFileService.getOneCfgExttree(guid);
        cfgDb = selectCfgDbOne(cfgExttree.getDtDbKey());
        List<TreeConfig> list = new ArrayList<>();
//        String key = "TREE_CONFIG_ALL" + guid;
        if (Integer.parseInt(String.valueOf(cfgExttree.getIslazyload())) == 1) {
            if (cfgExttree.getIsusetop() == 0) {
                System.out.println("慢加载 不用顶级节点");
                BaseTreeconfig baseTreeconfig = getBaseTreeCacheOne(guid, 1);
                CfgTable cfgTable = selectCfgTableOne(baseTreeconfig.getDtConfigId());
                String sqlString = "";
                if (baseTreeconfig.getQueryCon() == null) {
                    sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                            + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + 0 + " " + "AS PID FROM "
                            + cfgTable.getDtName();
                } else {
                    sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                            + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + 0 + " " + "AS PID FROM "
                            + cfgTable.getDtName() + " " + "WHERE 1=1" + " " + baseTreeconfig.getQueryCon();
                }
                List<Map<String, Object>> list2 = executequerySql(cfgDb, sqlString);
                for (Map<String, Object> m : list2) {
                    TreeConfig treeConfig = new TreeConfig();
                    treeConfig.setId((String) m.get("ID"));
                    treeConfig.setName((String) m.get("NAME"));
                    treeConfig.setPid("1");
                    list.add(treeConfig);
                }
                String extendStr = JSON.toJSONString(list);
                return extendStr;
//                redisCacheService.saveObject(key, extendStr, rdi);
//                redisCacheService.setKeyTimeOut(key, cfgExttree.getCatchtime(), rdi);
            } else {
                System.out.println("慢加载用顶级节点");
                List<TreeConfig> configs = new ArrayList<>();
                TreeConfig treeCon = new TreeConfig();
                treeCon.setId("1");
                treeCon.setName(cfgExttree.getTopnode());
                treeCon.setPid("0");
                list.add(treeCon);
                BaseTreeconfig baseTreeconfig = getBaseTreeCacheOne(guid, 1);
                CfgTable cfgTable = selectCfgTableOne(baseTreeconfig.getDtConfigId());
                String sqlString = "";
                if (baseTreeconfig.getQueryCon() == null) {
                    sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                            + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + 1 + " " + "AS PID FROM "
                            + cfgTable.getDtName();
                } else {
                    sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                            + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + 1 + " " + "AS PID FROM "
                            + cfgTable.getDtName() + " " + "WHERE 1=1" + " " + baseTreeconfig.getQueryCon();

                }
                List<Map<String, Object>> list2 = executequerySql(cfgDb, sqlString);
                for (Map<String, Object> m : list2) {
                    TreeConfig treeConfig = new TreeConfig();
                    treeConfig.setId((String) m.get("ID"));
                    treeConfig.setName((String) m.get("NAME"));
                    treeConfig.setPid("1");
                    configs.add(treeConfig);
                }
                treeCon.setChildren(configs);
                String extendStr = JSON.toJSONString(treeCon);
                return extendStr;
//                redisCacheService.saveObject(key, extendStr, rdi);
//                redisCacheService.setKeyTimeOut(key, cfgExttree.getCatchtime(), rdi);
            }
        } else {
            if (cfgExttree.getIsusetop() == 0) {
                List<BaseTreeconfig> baseTreeconfigLists = getBaseTreeCache(guid);
                TreeMap<Integer, BaseTreeconfig> treeMaping = new TreeMap<Integer, BaseTreeconfig>();
                for (BaseTreeconfig bs : baseTreeconfigLists) {
                    treeMaping.put(bs.getGrade(), bs);
                }
                List<BaseTreeconfig> baseTreeconfigList = new ArrayList<>();
                for (Map.Entry<Integer, BaseTreeconfig> entry : treeMaping.entrySet()) {
                    baseTreeconfigList.add(entry.getValue());
                }
                Map<String, Object> map = new HashMap<>();
                List<TreeConfig> tList = new ArrayList<>();
                String sql = "";
                int a = 1;
                Map<String, List<TreeConfig>> conMap = new HashMap<>();
                List<TreeConfig> lConfigs = new ArrayList<>();
                for (BaseTreeconfig b : baseTreeconfigList) {
                    CfgTable cfgTable = selectCfgTableOne(b.getDtConfigId());
                    if (b.getGrade() == 1) {
                        sql = "SELECT " + b.getFieldKey() + " " + "AS ID," + " " + b.getFieldShow() + " " + "AS NAME,"
                                + " " + 0 + " " + "AS PID FROM " + cfgTable.getDtName();
                        System.out.println(sql);
                        List<Map<String, Object>> lists = executequerySql(cfgDb, sql);
                        List<String> conList = new ArrayList<>();
                        for (Map<String, Object> mp : lists) {
                            TreeConfig treeConfig = new TreeConfig();
                            conList.add((String) mp.get("ID"));
                            treeConfig.setId((String) mp.get("ID"));
                            treeConfig.setName((String) mp.get("NAME"));
                            treeConfig.setPid("0");
                            tList.add(treeConfig);
                            lConfigs.add(treeConfig);
                        }
                        int grade = 2;
                        for (TreeConfig treeConfig : lConfigs) {
                            List<TreeConfig> n = recursiveTree(treeConfig.getId(), baseTreeconfigLists, grade + 1,
                                    cfgTable.getDtName()); // 递归
                            treeConfig.setChildren(n);
                        }
                    }
                }
                String extendStr = JSON.toJSONString(lConfigs);
                return extendStr;
//                redisCacheService.saveObject(key, extendStr, rdi);
//                redisCacheService.setKeyTimeOut(key, cfgExttree.getCatchtime(), rdi);
            } else {
                System.out.println("全加载用顶级节点");
                TreeConfig treeCon = new TreeConfig();
                treeCon.setId("1");
                treeCon.setName(cfgExttree.getTopnode());
                treeCon.setPid("0");
                list.add(treeCon);
                List<BaseTreeconfig> baseTreeconfigLists = getBaseTreeCache(guid);
                TreeMap<Integer, BaseTreeconfig> treeMaping = new TreeMap<Integer, BaseTreeconfig>();
                for (BaseTreeconfig bs : baseTreeconfigLists) {
                    treeMaping.put(bs.getGrade(), bs);
                }
                List<BaseTreeconfig> baseTreeconfigList = new ArrayList<>();
                for (Map.Entry<Integer, BaseTreeconfig> entry : treeMaping.entrySet()) {
                    baseTreeconfigList.add(entry.getValue());
                }
                Map<String, Object> map = new HashMap<>();
                List<TreeConfig> tList = new ArrayList<>();
                String sql = "";
                int a = 1;
                Map<String, List<TreeConfig>> conMap = new HashMap<>();
                List<TreeConfig> lConfigs = new ArrayList<>();
                for (BaseTreeconfig b : baseTreeconfigList) {
                    CfgTable cfgTable = selectCfgTableOne(b.getDtConfigId());
                    if (b.getGrade() == 1) {
                        sql = "SELECT " + b.getFieldKey() + " " + "AS ID," + " " + b.getFieldShow() + " " + "AS NAME,"
                                + " " + 0 + " " + "AS PID FROM " + cfgTable.getDtName();
                        System.out.println(sql);
                        List<Map<String, Object>> lists = executequerySql(cfgDb, sql);
                        List<String> conList = new ArrayList<>();
                        for (Map<String, Object> mp : lists) {
                            TreeConfig treeConfig = new TreeConfig();
                            conList.add((String) mp.get("ID"));
                            treeConfig.setId((String) mp.get("ID"));
                            treeConfig.setName((String) mp.get("NAME"));
                            treeConfig.setPid("1");
                            treeConfig.setGrade(1);
                            tList.add(treeConfig);
                            lConfigs.add(treeConfig);
                        }
                        int grade = 2;
                        for (TreeConfig treeConfig : lConfigs) {
                            List<TreeConfig> n = recursiveTree(treeConfig.getId(), baseTreeconfigLists, grade,
                                    cfgTable.getDtName()); // 递归
                            treeConfig.setChildren(n);
                            grade++;
                        }
                    }
                }
                treeCon.setChildren(lConfigs);
                String extendStr = JSON.toJSONString(treeCon);
                return extendStr;
//                redisCacheService.saveObject(key, extendStr, rdi);
//                redisCacheService.setKeyTimeOut(key, cfgExttree.getCatchtime(), rdi);
            }
        }

    }

    public List<TreeConfig> recursiveTree(String pid, List<BaseTreeconfig> btcList, int grade, String tableName) {
        TreeConfig node = new TreeConfig();
        BaseTreeconfig baseTree = null;
        for (BaseTreeconfig baseTreeconfig : btcList) {
            if (grade == baseTreeconfig.getGrade()) {
                baseTree = baseTreeconfig;
                break;
            }
        }
        if (baseTree == null) {
            return null;
        }
        CfgTable cfgTable = selectCfgTableOne(baseTree.getDtConfigId());
        String sql = "SELECT " + baseTree.getFieldKey() + " " + "AS ID," + " " + baseTree.getFieldShow() + " "
                + "AS NAME," + "'" + pid + "'" + "AS PID FROM " + cfgTable.getDtName() + " " + "WHERE  "
                + baseTree.getFieldPKey() + " = '" + pid + "'";
        List<Map<String, Object>> lists = executequerySql(cfgDb, sql);
        List<TreeConfig> list = new ArrayList<>();
        for (Map<String, Object> map : lists) {
            TreeConfig treeConfig = new TreeConfig();
            treeConfig.setId((String) map.get("ID"));
            treeConfig.setName((String) map.get("NAME"));
            treeConfig.setPid(pid);
            treeConfig.setGrade(grade);
            list.add(treeConfig);
        }
        for (TreeConfig treeConfig : list) {
            List<TreeConfig> n = recursiveTree(treeConfig.getId(), btcList, grade + 1, tableName); // 递归
            treeConfig.setChildren(n);
        }
        return list;
    }

    public Object getOneGrade(String ServiceId) {
        String guid = ServiceId;
        CfgExttree cfgExttree = treeConfigFileService.getOneCfgExttree(guid);
        cfgDb = selectCfgDbOne(cfgExttree.getDtDbKey());
        List<BaseTreeconfig> baseTreeconfigLists = getBaseTreeCache(ServiceId);
        BaseTreeconfig baseTreeconfigs = null;
        String sql = "";
        int as = 2;
        for (BaseTreeconfig b : baseTreeconfigLists) {
            if (b.getGrade() == as) {
                baseTreeconfigs = b;
            }
        }
        List<TreeConfig> list = new ArrayList<>();
        if (cfgExttree.getIsusetop() == 0) {
            System.out.println("慢加载 不用顶级节点");
            BaseTreeconfig baseTreeconfig = getBaseTreeCacheOne(guid, 1);
            CfgTable cfgTable = selectCfgTableOne(baseTreeconfig.getDtConfigId());
            String sqlString = "";
            if (baseTreeconfig.getQueryCon() == null) {
                sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                        + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + baseTreeconfig.getFieldPKey() + " "
                        + "AS PID FROM " + cfgTable.getDtName();
            } else {
                sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                        + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + baseTreeconfig.getFieldPKey() + " "
                        + "AS PID FROM " + cfgTable.getDtName() + " " + "WHERE 1=1" + " "
                        + baseTreeconfig.getQueryCon();
            }
            List<Map<String, Object>> list2 = executequerySql(cfgDb, sqlString);
            for (Map<String, Object> m : list2) {
                TreeConfig treeConfig = new TreeConfig();
                treeConfig.setId((String) m.get("ID"));
                treeConfig.setName((String) m.get("NAME"));
                treeConfig.setPid("1");
                treeConfig.setGrade(1);
                if (baseTreeconfigs == null) {
                    treeConfig.setIsParent(false);
                } else {
                    treeConfig.setIsParent(true);
                }
                list.add(treeConfig);
            }
            return list;
        } else {
            System.out.println("慢加载用顶级节点");
            List<TreeConfig> configs = new ArrayList<>();
            TreeConfig treeCon = new TreeConfig();
            treeCon.setId("1");
            treeCon.setName(cfgExttree.getTopnode());
            treeCon.setPid("0");
            list.add(treeCon);
            BaseTreeconfig baseTreeconfig = getBaseTreeCacheOne(guid, 1);
            CfgTable cfgTable = selectCfgTableOne(baseTreeconfig.getDtConfigId());
            String sqlString = "";
            if (baseTreeconfig.getQueryCon() == null) {
                sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                        + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + baseTreeconfig.getFieldPKey() + " "
                        + "AS PID FROM " + cfgTable.getDtName();
            } else {
                sqlString = "SELECT " + baseTreeconfig.getFieldKey() + " " + "AS ID," + " "
                        + baseTreeconfig.getFieldShow() + " " + "AS NAME," + " " + baseTreeconfig.getFieldPKey() + " "
                        + "AS PID FROM " + cfgTable.getDtName() + " " + "WHERE 1=1" + " "
                        + baseTreeconfig.getQueryCon();

            }
            List<Map<String, Object>> list2 = executequerySql(cfgDb, sqlString);
            for (Map<String, Object> m : list2) {
                TreeConfig treeConfig = new TreeConfig();
                treeConfig.setId((String) m.get("ID"));
                treeConfig.setName((String) m.get("NAME"));
                treeConfig.setPid("1");
                treeConfig.setGrade(1);
                if (baseTreeconfigs == null) {
                    treeConfig.setIsParent(false);
                } else {
                    treeConfig.setIsParent(true);
                }
                configs.add(treeConfig);
            }
            treeCon.setChildren(configs);
            return treeCon;
        }
    }

}
